close all;
diameter = 20;
r = diameter / 2;
d = 3;
cluster_size = 300;
cluster_num = 2;
dendo = 0;
centers = get_4_tanget_spheres_centers(r);
C1 = create_cluster(centers(1,:)', r*ones(3,1), cluster_size);
C2 = create_cluster(centers(2,:)', r*ones(3,1), cluster_size);
C3 = create_cluster(centers(3,:)', r*ones(3,1), cluster_size);
%C4 = create_cluster(centers(4,:)', (r/2)*ones(3,1), cluster_size);

C = [C1, C2, C3];
my_ones = ones(1,cluster_size);
generated_class = [my_ones, 2*my_ones, 3*my_ones];

scatter3(C(1,:), C(2,:), C(3,:), [], generated_class','filled');
axis equal;

figure;
hold on;
for i=1:3
    [X,Y,Z] = sphere();
    [X,Y,Z] = shift_sphere(X,Y,Z,centers(i,:),r);
    mesh(X,Y,Z);
end
hold off;
axis equal;
xlabel('X');
ylabel('Y');


%K-means
figure;
class = kmeans(C', cluster_num, 'replicates', 6);
scatter3(C(1,:), C(2,:), C(3,:),[], class', 'filled');
axis equal;
rand_index = RandIndex(generated_class, class);
t = sprintf('K-means results\n Rand Index = %f\n 3 clusters', rand_index);
title(t);

%Hirerarchical - NN
Y = pdist(C','euclid'); 
Z = linkage(Y,'single'); 
T = cluster(Z, 'maxclust', cluster_num);
if (dendo == 1)
    figure;
    dendrogram(Z);
end

figure;
scatter3(C(1,:), C(2,:), C(3,:),[], T', 'filled');
axis equal;
rand_index = RandIndex(generated_class, T);
t = sprintf('Hierarchical results - NN\n RandIndex = %f', rand_index);
title(t);

%Hirerarchical - FN
figure;
Y = pdist(C','euclid'); 
Z = linkage(Y,'complete'); 
T = cluster(Z, 'maxclust', cluster_num);

if (dendo == 1)
    dendrogram(Z);
    figure;
end

scatter3(C(1,:), C(2,:), C(3,:),[], T', 'filled');
axis equal;
rand_index = RandIndex(generated_class, class);
t = sprintf('Hierarchical results - FN\n RandIndex = %f', rand_index);
title(t);
xlabel('X');
ylabel('Y');
zlabel('Z');



